clear all
set more off, perm
set maxvar 120000
set varabbrev off
* ---------------------------------------------- *
global dir 	"`1'"
global Data 	$dir/Data
global Tables 	$dir/Tables
global Figures 	$dir/Figures
global Work 	$dir/Work
global Temp 	$dir/Temp
global Pseudo	$dir/Work/Temp
* ---------------------------------------------- *
* Table 3 -- Panel A (returns on EBRs)
foreach PORTF in BOOK  {
use $Work/portfolio_`PORTF'_qnic, clear
tsset portf datem

gen cumQ=.
gen cumQMkt=.
	
eststo clear
foreach x of numlist 6  {
replace cumQ=cumQRetMo1	
eststo Mo1_`x': quietly: ivreg2 cumNRetMo1 cumQ if portf==`x', bw(1 ) robust   small

replace cumQ=cumQRetQr1	
eststo Qr1_`x': quietly: ivreg2 cumNRetQr1 cumQ if portf==`x', bw(4 ) robust small

replace cumQ=cumQRetYr1	
eststo Yr1_`x': quietly: ivreg2 cumNRetYr1 cumQ if portf==`x', bw(13)robust small

replace cumQ=cumQRetYr3	
eststo Yr3_`x': quietly: ivreg2 cumNRetYr3 cumQ if portf==`x', bw(37)robust small

replace cumQ=cumQRetYr5	
eststo Yr5_`x': quietly: ivreg2 cumNRetYr5 cumQ if portf==`x', bw(61)robust small
}
if "`PORTF'"=="BOOK" {
esttab Mo1_* Qr1_* Yr1_* Yr3_* Yr5_* using $Tables/Table03_June.csv,  nonotes compress b(4) se(4) star(c 0.10 b 0.05 a 0.01) nolabel nogap ar2 title(`PORTF') replace
	}
if "`PORTF'"!="BOOK" {
esttab Mo1_* Qr1_* Yr1_* Yr3_* Yr5_* using $Tables/Table03_June.csv,  nonotes compress b(4) se(4) star(c 0.10 b 0.05 a 0.01) nolabel nogap ar2 title(`PORTF') append
}
* Table 3 -- Panel B 
* Below we add the market EBR 
eststo clear
foreach x of numlist 6  {
replace cumQ=cumQRetMo1	
replace cumQMkt=cumQMktMo1	
eststo Mo1_`x': quietly: ivreg2 cumNRetMo1 cumQ cumQMkt if portf==`x', bw(1 ) robust small

replace cumQ=cumQRetQr1	
replace cumQMkt=cumQMktQr1	
eststo Qr1_`x': quietly: ivreg2 cumNRetQr1 cumQ cumQMkt if portf==`x', bw(4 ) robust small

replace cumQ=cumQRetYr1	
replace cumQMkt=cumQMktYr1	
eststo Yr1_`x': quietly: ivreg2 cumNRetYr1 cumQ cumQMkt if portf==`x', bw(13)robust small

replace cumQ=cumQRetYr3	
replace cumQMkt=cumQMktYr3	
eststo Yr3_`x': quietly: ivreg2 cumNRetYr3 cumQ cumQMkt if portf==`x', bw(37)robust small

replace cumQ=cumQRetYr5	
replace cumQMkt=cumQMktYr5	
eststo Yr5_`x': quietly: ivreg2 cumNRetYr5 cumQ cumQMkt if portf==`x', bw(61)robust small
}
esttab Mo1_* Qr1_* Yr1_* Yr3_* Yr5_* using $Tables/Table03_June.csv,  nonotes compress b(4) se(4) star(c 0.10 b 0.05 a 0.01) nolabel nogap ar2 title(`PORTF') append 
}
